package com.ruoyi.heytalk.controller.common;

import com.ruoyi.common.constant.heytalk.CommonConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.heytalk.dto.LoginDTO;
import com.ruoyi.common.core.domain.heytalk.dto.RegisterDTO;
import com.ruoyi.heytalk.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录控制层
 * @author zhusy
 * @since 2021/10/28
 */
@Api(value = "用户权限控制层", tags = {"用户权限控制层"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping(CommonConstants.HEY_TALK)
public class LoginController extends BaseController {

    private final LoginService loginService;

    @ApiOperation("用户名密码普通登录")
    @PostMapping("/login")
    public AjaxResult<Object> login(@Validated @RequestBody LoginDTO loginDTO) {
        return loginService.login(loginDTO);
    }

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public AjaxResult<Void> register(@Validated @RequestBody RegisterDTO registerDTO) {
        return loginService.register(registerDTO);
    }

    @ApiOperation("退出登录")
    @PostMapping("/logout")
    public AjaxResult<Void> logout(){
        return loginService.logout();
    }



}
